package Base;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Savepoint;

public class DatabaseManager
{

	private Connection connection;
	private Savepoint svpt;

		//crea la conexion
	public DatabaseManager()
	{
		try {
			DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());

			openConnectionTo("jdbc:oracle:thin:@localhost:1521:bases1");


		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void commit()
	{
		try
		{
			connection.commit();
			svpt = connection.setSavepoint();
		} catch (SQLException e)
		{
			e.printStackTrace();
		}
	}

	public Connection getConnection()
	{
		return connection;
	}

	public void openConnectionTo(String url)
	{

		try
		{			
			connection = DriverManager.getConnection(url, "system", "bases1");
		} catch (SQLException e)
		{
			e.printStackTrace();
		}

	}

	public void rollBack()
	{
		try
		{
			if (svpt != null)
			{
				connection.rollback(svpt);
				connection.commit();
			}
		} catch (SQLException e)
		{
			// TODO Errors?
			e.printStackTrace();
		}
	}

}
